﻿<Window x:Class="mskold.TfsAdminToolKit.Views.FolderSizes"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="clr-namespace:mskold.TfsAdminToolKit.ViewModels"
        xmlns:src="clr-namespace:Sogeti.SourceControlWrapper"
        Title="FolderSizes" Height="517" Width="583"  Loaded="Window_Loaded">
    <Window.DataContext >
        <vm:FolderSizesViewModel />
    </Window.DataContext>
    <Window.Resources>
        <Style x:Key="RightAlignCell" TargetType="{x:Type DataGridCell}">
            <Setter Property="HorizontalAlignment" Value="Right"/>
        </Style>
        <!--<HierarchicalDataTemplate DataType="{x:Type src:SCFolder}"   ItemsSource="{Binding Path=Folders}">
            <StackPanel Orientation="Horizontal">
                <Label Name="tvNode" Padding="2" Content="{Binding Path=FolderName}" />
                <Label Name="lblSize" Padding="2" Content="{Binding Path=SizeTxt}" />
            </StackPanel>
            <HierarchicalDataTemplate.Triggers>

            </HierarchicalDataTemplate.Triggers>
        </HierarchicalDataTemplate>-->
        <src:DivideBy2Converter x:Key="DivideBy2Converter" />
        <src:FileSizeConverter x:Key="FileSizeConverter" />

        <Style x:Key="StretchItem" TargetType="{x:Type StackPanel}">
            <Setter Property="HorizontalAlignment" Value="Stretch"/>
        </Style>

        <HierarchicalDataTemplate x:Key="NodeFolderTemplate" ItemsSource="{Binding Path=Folders}" >
            <StackPanel Orientation="Horizontal"  Style="{StaticResource StretchItem}">
                <Label Name="tvNode" HorizontalAlignment="Left" Width="{Binding Path=ActualWidth, Converter={StaticResource DivideBy2Converter}, ConverterParameter=0.6, RelativeSource={RelativeSource FindAncestor, AncestorType=TreeView, AncestorLevel=1}}" Padding="2" Content="{Binding Path=FolderName}" />
                <Label Name="lblSize" HorizontalAlignment="Right" Width="60" Padding="2" Content="{Binding Path=SizeTxt}" HorizontalContentAlignment="Right" />
            </StackPanel>
        </HierarchicalDataTemplate>


        <HierarchicalDataTemplate x:Key="NodeProjectTemplate" ItemsSource="{Binding Path=Folders}" ItemTemplate="{StaticResource NodeFolderTemplate}">

            <StackPanel Orientation="Horizontal"  Style="{StaticResource StretchItem}">
                <CheckBox Name="chkScan" IsChecked="{Binding IsSelected, Mode=TwoWay}"  Visibility="Visible"  VerticalAlignment="Center"/>
                <Label Name="tvNode" HorizontalAlignment="Left" Width="{Binding Path=ActualWidth, Converter={StaticResource DivideBy2Converter}, ConverterParameter=0.6, RelativeSource={RelativeSource FindAncestor, AncestorType=TreeView, AncestorLevel=1}}" Padding="2" Content="{Binding Path=FolderName}"  VerticalAlignment="Center"/>
                <Label Name="lblSize" HorizontalAlignment="Right" Width="60" Padding="2" Content="{Binding Path=SizeTxt}" HorizontalContentAlignment="Right"  VerticalAlignment="Center" />
            </StackPanel>
        </HierarchicalDataTemplate>


        <HierarchicalDataTemplate x:Key="NodeTemplate"  ItemsSource="{Binding Path=Folders}" ItemTemplate="{StaticResource NodeProjectTemplate}">
            <StackPanel Orientation="Horizontal"  Style="{StaticResource StretchItem}">
                <CheckBox Name="chkAll" IsChecked="{Binding IsSelected}"  Visibility="Visible" Click="chkAll_Click" VerticalAlignment="Center"/>
                <Label Name="tvNode" HorizontalAlignment="Left" Width="{Binding Path=ActualWidth, Converter={StaticResource DivideBy2Converter}, ConverterParameter=0.6, RelativeSource={RelativeSource FindAncestor, AncestorType=TreeView, AncestorLevel=1}}" Padding="2" Content="{Binding Path=FolderName}"  VerticalAlignment="Center"/>
                <Label Name="lblSize" HorizontalAlignment="Right" Width="60" Padding="2" Content="{Binding Path=SizeTxt}" HorizontalContentAlignment="Right"  VerticalAlignment="Center"/>
            </StackPanel>
        </HierarchicalDataTemplate>
        
    </Window.Resources>

    <Grid >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="3*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
        </Grid.RowDefinitions>
        <TreeView Grid.Column="0"  Margin="12,100,6,12" Name="treeView2"  ItemsSource="{Binding Path=RootFolder.Folders}" ItemTemplate="{StaticResource NodeTemplate}" SelectedItemChanged="treeView2_SelectedItemChanged">

        </TreeView>

        <ProgressBar Grid.Column="0" Grid.ColumnSpan="2" Height="16"  Name="progressBar" Margin="12,80,12,0" VerticalAlignment="Top" />
        <Label Grid.Column="0" Grid.ColumnSpan="2" Content="Label"  Padding="0" Margin="12,80,12,0" Name="lblProgress" VerticalAlignment="Top" FontSize="10" Opacity="1" HorizontalContentAlignment="Center" />
        <DataGrid AutoGenerateColumns="False" Grid.Column="1" HorizontalAlignment="Stretch" Margin="6,100,12,12" Name="dataGrid1" VerticalAlignment="Stretch" ItemsSource="{Binding Path=SelectedFolder.InclusiveFileTypes}" >
            <DataGrid.Columns>
                <DataGridTextColumn IsReadOnly="True" Header="Extension" Binding="{Binding Path=Key}" Width="*" />
                <DataGridTextColumn IsReadOnly="True" Header="Size" Binding="{Binding Path=Value, Converter={StaticResource FileSizeConverter}, Mode=OneTime}" CellStyle="{StaticResource RightAlignCell}" Width="*" MinWidth="30"/>
            </DataGrid.Columns>

        </DataGrid>
        <Button Name="cmdStart" Content="Start" HorizontalAlignment="Right" Margin="12,26,12,0" VerticalAlignment="Top" Width="80" Grid.Column="1" Click="cmdStart_Click"/>

    </Grid>
</Window>
